package io.github.maojian.str;

import org.junit.Test;

/**
 * @Auther: jian.mao
 * @Date: 2022/4/12 09:53
 * @Description:
 */
public class Q806 {
    private static final int WIDTH_MAX = 100;

    public int[] numberOfLines(int[] widths, String s) {
        int lineNum = 1, width = 0;
        for (int i = 0; i < s.length(); i++) {
            int curWidth = widths[s.charAt(i) - 'a'];
            width = width + curWidth;
            if (width > WIDTH_MAX) {
                width = curWidth;
                lineNum++;
            }
        }
        return new int[]{lineNum, width};
    }

    @Test
    public void test() {
        int[] widths = new int[]{10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
        String s = "abcdefghijklmnopqrstuvwxyz";
        int[] result = numberOfLines(widths, s);
        System.out.println(result[0] + "," + result[1]);
    }
}
